declare var wx: any;
declare var tt: any;
import { EnumplatFrom } from "./EnumplatFrom";
import Instance from "../Utils/Instance";
import SdkMgr from "./SdkMgr";
import { sys } from "cc";

export default class SdkTool {
    public sdk: SdkMgr = null;
    /**微信下玩家名字 */
    // public nickname: string = `www`;
    /**微信下玩家头像url */
    // public avatarUrl: string = `https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTIic4ZF5qVWSEKibOZdEAP3EyoGgxKicUcOTfUyLqrN5MN6PI9JkicKD6L8VWdQWRcWD8iapyl2BYrfW6Q/132?.jpg`;
    /**玩家token */
    // public token: string = `1234567890`;
    public uid: number = 111;
    /**玩家openid */
    public openid: string = `123123`;
    /**是否第一次进入游戏 */
    public isFirst: boolean = false;
    /**场景值 */
    public sceneAppId: number = 1;
    /**是否支持侧边栏 */
    public sidebar: boolean = false;
    /**侧边栏进入 */
    public isSidebar: boolean = false;
    public topmenu: number = 0;

    public static get ins(): SdkTool {
        return Instance.get(SdkTool);
    }
    public initSdk(): void {
        switch (this.platform) {
            case EnumplatFrom.TT:
                this.sdk = new SdkMgr(EnumplatFrom.TT);
                break;
            case EnumplatFrom.WX:
                this.sdk = new SdkMgr(EnumplatFrom.WX);
                break;
            case EnumplatFrom.PC:
                this.sdk = new SdkMgr(EnumplatFrom.PC);
                break;
        }
        this.sdk.init(null, null);
    }
    /**平台参数 */
    public get platform(): string {
        if (this.isInTt) {
            return EnumplatFrom.TT;
        }
        if (this.isInWeChat) {
            return EnumplatFrom.WX;
        }
        return EnumplatFrom.PC;
    }
    /**是否在微信小程序中 */
    public get isInWeChat() {
        return typeof wx !== 'undefined' && typeof tt == 'undefined';
    }
    /**是否在抖音小程序中 */
    public get isInTt() {
        return typeof tt !== 'undefined';
    }
    public getMenuButtonBoundingClientRect(): void {
        this.sdk.getMenuButtonBoundingClientRect();
    }
    /**
     * 设置即时通讯排名数据
     * @param val 排名数据
     */
    public setImRankData(val: number): void {
        this.sdk.setImRankData(val);
    }
    /**
     * 获取排行榜列表,抖音下自动渲染排行榜列表
     */
    public getImRankList(): void {
        this.sdk.getImRankList();
    }
    public get isShock(): number {
        var score = sys.localStorage.getItem(`linkisShock`);
        // console.log(score, `linkisShock`);
        if (score) {
            return Number(score);
        }
        return 2;
    }
    public set isShock(val: number) {
        sys.localStorage.setItem(`linkisShock`, val);
    }
    public playShock(): void {
        if (this.isShock != 1) {
            return;
        }
        this.sdk.vibrateShort();
    }
}